<#cenluan title="${blog.title}" menu="blog" validate="true">
	<div class="row">
		<div class="col-sm-8">
			<h3>
				<%if(blog.type=="ORIGINAL"){%>
					<span class="label label-primary hidden-xs">原创</span>
				<%}else if(blog.type=="COPY"){%>
					<span class="label label-success hidden-xs">转载</span>
				<%}%>
				<%if(blog.privacy){%>
					<span class="label label-warning hidden-xs">私有</span>
				<%}%>
				${blog.title,xss}
			</h3>
			<p class="text-muted small hidden-sm hidden-xs">
				${blog.creater.html}发表于${blog.updateTime,prettyTime}(${blog.updateTime,"yyyy-MM-dd HH:mm"})&nbsp;&nbsp;
				阅读（${blog.clickCount}）&nbsp;|&nbsp;收藏（<span class="favorite-count">${blog.favoriteCount}</span>）
				<%if(editable){%>
					&nbsp;&nbsp;<a href="/blog/edit/${blog.id}">编辑</a>
				<%}%>
				<%if(deletable){%>
					&nbsp;&nbsp;<a href="javascript:;" class="btn-del">删除</a>
				<%}%>
				<%if(session.user.id!=blog.createrId){%>
					<%if(favorited){%>
						&nbsp;&nbsp;
						<a href="javascript:;" class="favorite favorite-remove">
							<span class="text">取消收藏</span>
						</a>
					<%}else{%>
						&nbsp;&nbsp;
						<a href="javascript:;" class="favorite favorite-add">
							<span class="text">我要收藏</span>
						</a>
					<%}%>
				<%}%>
			</p>
			<p class="text-muted small visible-xs">
				${blog.updateTime,"yyyy-MM-dd"}&nbsp;&nbsp;${blog.creater.html}
			</p>
			<hr class="mt0">
			<div class="blog-content">
				${blog.htmlContent}
			</div>
			<%if(blog.type=="COPY"){%>
				<p class="text-success">原文链接：<a href="${blog.referer}">${blog.referer}</a></p>
			<%}%>
				<div class="btn-group btn-group-sm visible-xs clearfix mb20">
					<button class="btn btn-default disabled">
						<span class="glyphicon glyphicon-eye-open"></span>&nbsp;${blog.clickCount}
					</button>
					<button class="btn btn-default disabled">
						<span class="glyphicon glyphicon-star-empty"></span>&nbsp;${blog.favoriteCount}
					</button>
					<%if(editable){%>
					<a class="btn btn-default" href="/blog/edit/${blog.id}">
						<span class="glyphicon glyphicon-edit"></span>
					</a>
					<%}%>
					<%if(deletable){%>
					<button class="btn btn-default btn-del">
						<span class="glyphicon glyphicon-trash"></span>
					</button>
					<%}%>
					<%if(session.user.id!=blog.createrId){%>
						<%if(favorited){%>
							<button class="btn btn-default favorite favorite-remove">
								<span class="glyphicon glyphicon-star"></span>&nbsp;
								<span class="favorite-count">${blog.favoriteCount}</span>
							</button>
						<%}else{%>
							<button class="btn btn-default favorite favorite-add">
								<span class="glyphicon glyphicon-star-empty"></span>&nbsp;
								<span class="favorite-count">${blog.favoriteCount}</span>
							</button>
						<%}%>
					<%}%>	
				</div>
			<script>
				$(function(){
					$(".btn-del").click(function(){
						if(!confirm("确定要将笔记删除吗？")){
							return;
						}
						$.getJSON("/blog/delete/${blog.id}",function(json){
							if(!json.ok){
								alert(json.msg);
								return;
							}
							location="/blog";
						});
					});
					$(".container").on("click",".favorite-remove",function(){
						$.getJSON("/blog/favorite/delete/${blog.id}",function(json){
							if(!json.ok){
								alert(json.msg);
								return;
							}
							$(".favorite-count").text(json.count);
							var favoriteBtn = $(".favorite"); 
							favoriteBtn.removeClass("favorite-remove").addClass("favorite-add");
							favoriteBtn.find(".glyphicon").removeClass("glyphicon-star").addClass("glyphicon-star-empty");
							favoriteBtn.find(".text").text("我要收藏");
						});
					});
					$(".container").on("click",".favorite-add",function(){
						var $this = $(this);
						$.getJSON("/blog/favorite/save/${blog.id}",function(json){
							if(!json.ok){
								alert(json.msg);
								return;
							}
							$(".favorite-count").text(json.count);
							var favoriteBtn = $(".favorite"); 
							favoriteBtn.removeClass("favorite-add").addClass("favorite-remove");
							favoriteBtn.find(".glyphicon").removeClass("glyphicon-star-empty").addClass("glyphicon-star");
							favoriteBtn.find(".text").text("取消收藏");
						});
					});
				});
			</script>
			<!-- 评论 -->
			<h4 class="page-header">网友评论${blog.commentCount}条</h4>
			<%for(comment in page.list){%>
				<%include("/blog/comment/show.html",{blog:blog,comment:comment}){}%>
				<%if(!commentLP.last){%>
					<hr class="dashed">
				<%}%>
			<%}%>
			<div id="pager">${pageLink}</div>
			<!-- 发表评论 -->
			<form class="mt20" method="post" action="/blog/comment/save" id="commentForm">
				<input type="hidden" name="blogComment.blogId" value="${blog.id}">
				<div class="form-group">
					<textarea class="form-control" rows="5" placeholder="说点什么吧" style="resize:vertical;"
						 required minlength="1" maxlength="200" name="blogComment.content" id="commentContent"></textarea>
				</div>
				<div class="row">
					<div class="col-xs-4">
						<button class="btn btn-primary btn-sm btn-block" type="submit">发表</button>
					</div>
					<div class="col-xs-8">
						<label class="checkbox-inline">
							<input type="checkbox" name="showLog" value="true" checked="checked">同时在我的动态里显示
						</label>
					</div>
				</div>
			</form>
			<script>
				$("#commentForm").validate({
					submitHandler : function(form) {
						$(form).find(":submit").button("loading");
						$(form).ajaxSubmit({
							url : "/blog/comment/save",
							success : function(json) {
								if (!json.ok) {
									alert(json.msg);
								} else {
									$(form).resetForm();
									$.get("/blog/comment/show/" + json.id, function(data) {
										if ($(".blog-comment").length) {
											$("#pager").before("<hr class='dashed'>");
										}
										$("#pager").before(data);
									}, "html");
								}
								$(form).find(":submit").button("reset");
							}
						});
					}
				});
				function rpl(nickname) {
					$("#commentContent").val($("#commentContent").val() + "@" + nickname + " ");
					$("#commentContent").focus();
				}
				function deleteComment(id) {
					if (!confirm("确定要将这条评论删除吗？")) {
						return;
					}
					$.getJSON("/blog/comment/delete/" + id, function(json) {
						if (!json.ok) {
							alert(json.msg);
							return;
						}
						var comment = $("#" + id);
						if (comment.next("hr").length) {
							comment.next("hr").remove();
						} else {
							comment.prev("hr").remove();
						}
						comment.remove();
						if (!$(".blog-comment").length) {
							location = "/blog/show/${blog.id}";
						}
					});
				}
			</script>
		</div><!-- col -->
	</div><!-- row -->
</#cenluan>